<?php

namespace App\JsonRpc;

use Hyperf\RpcClient\AbstractServiceClient;
use Hyperf\CircuitBreaker\Annotation\CircuitBreaker;

class RpcServerConsumer extends AbstractServiceClient implements RpcServerInterface
{
    /**
     * 定义对应服务提供者的服务名称
     * @var string
     */
    protected $serviceName = 'RpcServer';

    /**
     * 定义对应服务提供者的服务协议
     * @var string
     */
    protected $protocol = 'jsonrpc';

    /**
     * @CircuitBreaker(timeout=0.00007, failCounter=1, successCounter=1, fallback="App\JsonRpc\RpcServerInterface::addFallback")
     */
    public function add(int $a, int $b)
    {
        return $this->__request(__FUNCTION__, compact('a', 'b'));
    }

    public function addFallback(int $a, int $b)
    {
        return 'fallback';
    }
}
